/*
 * @Author: your name
 * @Date: 2021-06-19 10:46:49
 * @LastEditTime: 2021-07-08 15:35:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \saas\store\modules\yzhvideoHelper.js
 */
import api from "@/common/api";
import config from '@/config';
const state = {
    userInfo:null
  }
  const mutations = {
    //设置state
    SET_STATE(state, data) {
        Object.assign(state, data);
    },
  }
  const actions = {
      //获取用户信息
      async getUserInfo({ commit, state, dispatch }) {
         const {data,code} = await api.yzhvideo.helperA2.getUsersInfo();
         commit('SET_STATE',{userInfo:data})
         uni.setStorageSync('userInfo', data)
         return code
      },
      //登录
      async login({ commit, state, dispatch }) {
       return new Promise((reslove, reject) => {
           uni.login({
               provider: "weixin",
               success: async (wxRes) => {
                   let res = await api.yzhvideo.helperA2.userLogin({
                       code: wxRes.code,
                       app_id: config.appid,
                   });
                  
                   if (res.code == 200) {
                       
                       this.commit("SET_TOKEN", res.data.token);
                       uni.setStorageSync("UserInfoData", res.data);
                       uni.$emit('loginOk')
                       reslove(res);
                   }
               },
           });
       });
       
     },
  };
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  }
  